package cc.web.vaaking.common;

import cc.web.vaaking.entity.SysUser;
import cc.web.vaaking.services.SysRoleService;
import cn.hutool.log.StaticLog;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

public class LoginContext {
    /**
     * 获取当前登录用户
     *
     * @return
     */
    public static LoginUser getCurrentUser() {

        String id = RequestContext.get().getSession().getId();
        LoginUser user = (LoginUser) SysCache.getCache(id);
        return user;
    }

    /**
     * 设置当前用户
     *
     * @param request
     * @param loginUser
     */
    public static void setCurrentUser(HttpServletRequest request, LoginUser loginUser) {
        HttpSession session = request.getSession();
        String id = session.getId();
        SysCache.addCache(id, loginUser); //缓存 id与用户
//        SysCache.addCache(user.getAccount(),user);
    }

    /**
     * 移除当前用户，用户登出
     *
     * @param request
     */
    public static void removeCurrentUser(HttpServletRequest request) {
//        SysCache.removeCache(getCurrentUser(request).getAccount());
        SysCache.removeCache(request.getRequestedSessionId());
    }



}
